package com.jinhu.filter;

import com.jinhu.ResultEntity;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.exception.StatusException;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;

@Component(index = 0) //index 为顺序位（不加，则默认为0）
public class ErrorFilter implements Filter {
    @Override
    public void doFilter(Context ctx, FilterChain chain) throws Throwable {
        try {
            chain.doFilter(ctx);
        }catch (StatusException e) {

            e.printStackTrace();
            ctx.render(ResultEntity.no("页面出错"));
        }catch (RuntimeException e){
            e.printStackTrace();
            ctx.render(ResultEntity.no(e.getMessage()));
        } catch (Throwable e) {
            e.printStackTrace();
            ctx.render(ResultEntity.no( e.getMessage()));
        }
    }
} 